How to Alias Git log to Git lg

A quick search showed how easy it is to make a much better looking git log by using an alias.

git config --global alias.lg "log --graph --pretty=tformat:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --decorate=full"
    

Creating a Basic Git Log Alias

To create a basic alias for git log, you can use the following command:

git config --global alias.lg "log --graph --pretty=format:'%h - %s (%cr) <%an>' --abbrev-commit"

This command does the following:

  • --graph: Shows a text-based graph of the commit history.
  • --pretty=format:'%h - %s (%cr) <%an>': Customizes the log output format:
    • %h: Abbreviated commit hash.
    • %s: Commit message.
    • %cr: Commit date, relative to the current time.
    • <%an>: Author name.
  • --abbrev-commit: Shows only the abbreviated commit hash.

Enhancing the Git Log Alias

You can enhance the alias to include more information and add colors for better readability:

git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --decorate=full"

This enhanced alias includes:

  • %Cred%h%Creset: Colors the commit hash in red.
  • %C(auto)%d%Creset: Colors the branch and tag names automatically.
  • %Cgreen(%cr): Colors the commit date in green.
  • %C(bold blue)<%an>%Creset: Colors the author name in bold blue.
  • --decorate=full: Shows full ref names (branches, tags) in the log.

Customizing the Git Log Alias

You can further customize the alias to suit your preferences. Here are some additional options you can use:

  • %C(yellow)%d%Creset: Colors the branch and tag names in yellow.
  • %C(cyan)%ar%Creset: Colors the commit date in cyan and shows it in a relative format (e.g., "2 days ago").
  • %C(magenta)%an%Creset: Colors the author name in magenta.

For example, to create an alias that uses these customizations, you can use the following command:

git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %C(cyan)(%ar) %C(magenta)<%an>%Creset' --abbrev-commit --decorate=full"

Using the Git Log Alias

Once you have created the alias, you can use it by running:

git lg

This will display your commit history in the customized format you specified.

 

 

Check out some other Bands on Bandcamp.com. Crazy Fingers (Vancouver 1991), Flying Butt Pliers, and Hammy Ham Hands.

Proudly powered by a Text Editor, an Sftp client and some Internet Searches.

2024 dispelled.ca end of file.